//
//  YBQuestionnaireListTableViewCell.m
//  HomeDoorWay
//
//  Created by apple on 17/11/16.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "YBQuestionnaireListTableViewCell.h"

@interface YBQuestionnaireListTableViewCell ()

@property (nonatomic , strong) UIView * theContentView;
/**  标题  */
@property (nonatomic , strong) UILabel * cellTitleLabel;
/**  时间  */
@property (nonatomic , strong) UILabel * timeLabel;
/**  积分图片  */
@property (nonatomic , strong) UIImageView * logoImageView;
/**  积分  */
@property (nonatomic , strong) UILabel * pointLabel;

@property (nonatomic , strong) UIView * lineView;
@end

@implementation YBQuestionnaireListTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initMyCell];
    }
    return self;
}


-(void)initMyCell{
    self.theContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], [UIScreen zj_screenHeight])];
    self.theContentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.theContentView];
    [self.theContentView addSubview:self.cellTitleLabel];
    [self.theContentView addSubview:self.timeLabel];
    [self.theContentView addSubview:self.logoImageView];
    [self.theContentView addSubview:self.pointLabel];
    self.cellTitleLabel.sd_layout.leftSpaceToView(self.theContentView , ItemPX * 20).topSpaceToView(self.theContentView , ItemPX * 30).widthIs([UIScreen zj_screenWith] - ItemPX * 160).heightIs(1);
    
    self.timeLabel.sd_layout.leftSpaceToView(self.theContentView , ItemPX * 20).bottomSpaceToView(self.theContentView , ItemPX * 10).widthIs([UIScreen zj_screenWith] * 0.3).heightIs(ItemPX * 60);
    
    self.logoImageView.sd_layout.rightSpaceToView(self.theContentView , ItemPX * 20).bottomSpaceToView(self.theContentView , ItemPX * 25).widthIs(ItemPX * 30).heightIs(ItemPX * 30);
    
    self.pointLabel.sd_layout.rightSpaceToView(self.logoImageView , ItemPX * 5).bottomSpaceToView(self.theContentView , ItemPX * 10).widthIs([UIScreen zj_screenWith] * 0.3).heightIs(ItemPX * 60);
    
    
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(0 , ItemPX * 238, [UIScreen zj_screenWith], ItemPX * 2)];
    self.lineView.backgroundColor = [UIColor themeColor];
    [self.theContentView addSubview:self.lineView];
    self.lineView.sd_layout.leftSpaceToView(self.theContentView , 0).bottomSpaceToView(self.theContentView , 0).rightSpaceToView(self.theContentView , 0).heightIs(ItemPX * 2);
}


-(void)setModel:(YBQuestionnaireModel *)model
{
    _model = model;
    NSString * titleString = model.PSQ_TITLE ? model.PSQ_TITLE : @"";
    if (![model.PSQ_TITLE isEqualToString:@"建言献策"]) {
        if ([model.ANS_STATE integerValue] == 1) {
            titleString = [NSString stringWithFormat:@"[已答题] %@" ,titleString ];
        }
    }
    self.cellTitleLabel.sd_layout.leftSpaceToView(self.theContentView , ItemPX * 20).topSpaceToView(self.theContentView , ItemPX * 30).widthIs(model.titleSize.width + 1).heightIs(model.titleSize.height + 1);
    [self.cellTitleLabel updateLayout];
    
    NSMutableAttributedString * tempAttributeString = [[NSMutableAttributedString alloc]initWithString:titleString];
    if (![model.PSQ_TITLE isEqualToString:@"建言献策"] && [model.ANS_STATE integerValue] == 1) {
        [tempAttributeString addAttribute:NSForegroundColorAttributeName value:[UIColor zj_colorWithHexString:@"00b98d"] range:NSMakeRange(0, 5)];
    }
    self.cellTitleLabel.attributedText = tempAttributeString;
    
    if (model.UPDATETIME.length > 10) {
        self.timeLabel.text = [model.UPDATETIME substringToIndex:10];
    }
    else{
        self.timeLabel.text = model.UPDATETIME;
    }
    self.pointLabel.text = model.PSQ_POINT;
    if (self.isHomePageCell) {
        self.theContentView.frame = CGRectMake(ItemPX * 16, 0, [UIScreen zj_screenWith] - ItemPX * 32, model.cellHeight);
        self.contentView.backgroundColor = [UIColor zj_colorWithHexString:@"f0f1f2"];
        self.lineView.hidden = YES;
    }
    else{
        self.theContentView.frame = CGRectMake(0, 0, [UIScreen zj_screenWith], model.cellHeight);
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.lineView.hidden = NO;
    }
    
    if ([model.PSQ_TITLE isEqualToString:@"建言献策"]) {
        self.logoImageView.hidden = YES;
        self.pointLabel.hidden = YES;
    }
    else{
        self.logoImageView.hidden = NO;
        self.pointLabel.hidden = NO;
    }
}






-(UILabel *)cellTitleLabel
{
    if (!_cellTitleLabel) {
        _cellTitleLabel = [ToolClass creatLabelWithFrame:CGRectMake(0, 0, 1, 1) font:16 textColor:[UIColor textBlackColor] text:@""];
    }
    return _cellTitleLabel;
}

-(UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = [ToolClass creatLabelWithFrame:CGRectMake(0, 0, 1, 1) font:13 textColor:[UIColor textGrayColor] text:@""];
    }
    return _timeLabel;
}

-(UILabel *)pointLabel
{
    if (!_pointLabel) {
        _pointLabel = [ToolClass creatLabelWithFrame:CGRectMake(0, 0, 1, 1) font:14 textColor:[UIColor zj_colorWithHexString:@"fc5f30"] text:@""];
        _pointLabel.textAlignment = NSTextAlignmentRight;
    }
    return _pointLabel;
}


-(UIImageView *)logoImageView
{
    if (!_logoImageView) {
        _logoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _logoImageView.image = [UIImage imageNamed:@"wjdc_icon_jifen"];
    }
    return _logoImageView;
}


@end
